package com.googlecode.delivery.packager;

import java.io.File;

import com.googlecode.delivery.model.DeploymentUnit;

public class DeliveryTarget {

	private File deliveryDir = null;
	private File configDir = null;

	public DeliveryTarget(File buildDir, String type) {
		deliveryDir = new File(buildDir.getAbsolutePath() + "/"
				+ DeploymentUnit.DELIVERY_ROOT_DIR);
		deliveryDir.mkdirs();
		configDir = new File(getConfigPath(deliveryDir, type));
		configDir.mkdirs();
		assert (configDir.canWrite());
	}

	/**
	 * Gets the delivery config files absolute path depending on artifact type.
	 * 
	 * @param deliveryDir
	 * @param type
	 *            the artifact type : war, jar or ear.
	 * @return
	 */
	static String getConfigPath(File deliveryDir, String type) {
		String configPath = deliveryDir.getAbsolutePath() + "/" + type;
		if ("war".equals(type)) {
			configPath = configPath + "/WEB-INF/classes";
		}
		return configPath;
	}

	public File getDeliveryDir() {
		return deliveryDir;
	}

	public File getConfigDir() {
		return configDir;
	}
}
